<?php

namespace ajiho\helper;

class Str
{
    /**
     * 生成一个uuid字符串
     * @param string $prefix 前缀比如 'abc'
     * @return string
     */
    public static function uuid(string $prefix = ''): string
    {
        $chars = md5(uniqid(mt_rand(), true));
        $uuid = substr($chars, 0, 8);
        $uuid .= substr($chars, 8, 4);
        $uuid .= substr($chars, 12, 4);
        $uuid .= substr($chars, 16, 4);
        $uuid .= substr($chars, 20, 12);
        return $prefix . $uuid;
    }
}